package com.jfinal.weixin.sdk.api;
import java.util.Map;

import org.apache.log4j.Logger;

import com.jfinal.weixin.sdk.utils.HttpUtils;

import cn.com.dashihui.web.exception.SaveException;
public class MsgApi {
	
	private static Logger log = Logger.getLogger(MsgApi.class);
	private static ApiResult post(String baseUrl, String jsonStr) {
		String url = baseUrl + AccessTokenApi.getAccessTokenStr();
		String jsonResult = HttpUtils.post(url, jsonStr);
		return new ApiResult(jsonResult);
	}
	
	/**
	 * 无事件触发的情况下向用户推送一条消息
	 */
	private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=";
	
	
	public static ApiResult editWX_opinion(Map<String,Object> mapParam) throws SaveException{
		try {
			log.info("OPENID:::::"+mapParam.get("OPENID"));
			String jsonParam = "{\"touser\":\""+mapParam.get("OPENID")+"\",\"msgtype\": \"text\",\"text\": {\"content\": \""+mapParam.get("ANSWER_CONTENT")+"\"}}";
			log.info("jsonParam::::"+jsonParam);
			return post(sendMsgUrl, jsonParam);
		} catch (Exception e) {
			log.error(e.getMessage());
			throw new SaveException(e.getMessage(), e);
		}
	}
}
